<template>
	<view class="normal-login-container">
		<view class="WeChat" @click="login">微信登录</view>
		<view class="">
			<label class="radio">
				<radio :checked="isShow" color="#999" @click="changeShow" style="transform: scale(0.7);"/>
				选中
			</label>
			我已阅读并同意《用户服务协议》、《隐私政策》
		</view>
	</view>
</template>

<script>
import { login } from '@/api/login';
import { toast } from '@/utils/common';
export default {
	data() {
		return {
			isShow: false
		};
	},
	computed: {},

	methods: {
		// 隐私协议
		handlePrivacy() {
			let site = this.globalConfig.appInfo.agreements[0];
			this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
		},

		// 用户协议
		handleUserAgrement() {
			let site = this.globalConfig.appInfo.agreements[1];
			this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
		},

		// 微信一键登录
		async login() {
			if (!this.isShow) {
				toast('请同意用户服务协议与隐私政策');
			}
			// 获取code
			const wxLoginRes = await uni.login({
				provider: 'weixin',
				onlyAuthorize: true
			});
			// 获取token
			await this.$store.dispatch('Login', wxLoginRes[1].code);
			// 获取用户信息
			await this.$store.dispatch('GetInfo');
			// 返回
			const pages = getCurrentPages();
			if (pages.length > 1) {
				uni.navigateBack();
			} else {
				this.$tab.reLaunch('/pages/index');
			}
		},

		changeShow() {
			this.isShow = !this.isShow;
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #ffffff;
}

.normal-login-container {
	width: 100%;
	height: 100vh;
	.WeChat {
		margin:600rpx auto 60rpx;
		width: 300rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border: 1px solid black;
		font-size:40rpx;
		color: #fff;
		background-color: #000507;
		border-radius: 50rpx;
	}
	.radio{
		padding: 40rpx 0;
	}
}
</style>
